package com.yang.sysc.service;

import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 订单id生成器
 *
 * @author yanghongjun19
 * @date 2020/12/30
 **/
@Service
public class OrderIdGenerator {

    private int count = 0;

    public synchronized String fetchOrderId() {
        String orderId = "";
        try {
            TimeUnit.MILLISECONDS.sleep(5);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
            String format = simpleDateFormat.format(new Date());
            count++;
            orderId = format + "_" + count;
        } catch (Exception e) {

        }
        return orderId;
    }
}
